-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
DOC: Update the pandas.DataFrame.abs docstring #20194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DOC: Update the pandas.DataFrame.abs docstring #20194
Conversation
Improve description and returns, and added notes and examples.
pandas/core/generic.py
Outdated
|
||
Select rows with data closest to certian value using argsort (from | ||
`StackOverflow | ||
<http://stackoverflow.com/questions/17758023/return-rows-in-a-dataframe-closest-to-a-user-defined-number>`__). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably too long of a line. SO should have a "share" URL that is shorter.
pandas/core/generic.py
Outdated
@@ -7115,12 +7115,61 @@ def _tz_localize(ax, tz, ambiguous): | |||
# Numeric Methods | |||
def abs(self): | |||
""" | |||
Return an object with absolute value taken--only applicable to objects | |||
that are all numeric. | |||
Return a Series/DataFrame with absolute numeric value of each object. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you repalce "object" with "element"? That's our usual noun for items in a frame.
pandas/core/generic.py
Outdated
that are all numeric. | ||
Return a Series/DataFrame with absolute numeric value of each object. | ||
|
||
This function only applies to objects that are all numeric. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
objects -> elements
pandas/core/generic.py
Outdated
2 6 30 -30 | ||
3 7 40 -50 | ||
>>> a_value = 43.0 | ||
>>> df.loc[(df.c - a_value).abs().argsort()] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No reason to assign a_value
I think? Just subtract 43? I also don't know if the argsort
helps. It seems a bit complicated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The example fails if argsort()
is removed. Maybe it's not a good idea to provided that example. I thought it was a good idea because abs()
is commonly used with other functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs to merge in master. you have a lot of other commits here.
6e2badf
to
4165872
Compare
@jreback sorry I was playing around with Git. I fixed the issue. |
pandas/core/generic.py
Outdated
Notes | ||
----- | ||
For ``complex`` inputs, ``1.2 + 1j``, the absolute value is | ||
:math:`\\sqrt{ a^2 + b^2 }`. See the Python |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like something missing from the end here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I was going to referer to the Python documentation on complex
inputs but then realised that the user would already know about them.
pandas/core/generic.py
Outdated
|
||
Examples | ||
-------- | ||
Absolute numeric values in a ``Series``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for the quotes on Series
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
pandas/core/generic.py
Outdated
3 4.00 | ||
dtype: float64 | ||
|
||
Absolute numeric values in a ``Series`` with ``complex`` numbers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could add an example for a Series of timedelta64
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a pd.Timedelta
example.
Codecov Report
@@ Coverage Diff @@
## master #20194 +/- ##
=========================================
Coverage ? 91.72%
=========================================
Files ? 150
Lines ? 49162
Branches ? 0
=========================================
Hits ? 45096
Misses ? 4066
Partials ? 0
Continue to review full report at Codecov.
|
Thanks @myles |
Improve description and returns, and added notes and examples.
Checklist for the pandas documentation sprint (ignore this if you are doing
an unrelated PR):
scripts/validate_docstrings.py <your-function-or-method>
git diff upstream/master -u -- "*.py" | flake8 --diff
python doc/make.py --single <your-function-or-method>
Please include the output of the validation script below between the "```" ticks:
I feel there aren't any similar methods for the See Also section.